package com.tas.manager;

import com.tas.anno.AsyncMethod;
import com.tas.enums.StrategyEnum;
import org.noear.solon.core.aspect.Interceptor;
import org.noear.solon.core.aspect.Invocation;

/**
 * @author kevin
 */
public class AsyncInterceptor implements Interceptor {

  public static AsyncInterceptor instance = new AsyncInterceptor();
  @Override
  public Object doIntercept(Invocation inv) throws Throwable {
    //1. 获取策略
    AsyncMethod asyncMethod = inv.getMethodAnnotation(AsyncMethod.class);
    StrategyEnum strategy = asyncMethod.strategy();

    String method = inv.target().getClass() + "." + inv.method().getMethod().getName();
    Object[] args = inv.args();

    System.out.println("代理执行开始：" + method);
    //根据具体策略 执行
    Boolean executeResult = strategy.getStrategy().execute(method,args);

    if(executeResult){
      throw new RuntimeException("执行失败");
    }else{
      System.out.println("代理执行完成：" + method);
    }
    return true;
  }
}

